{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 3.5. Configuring the Jupyter Notebook"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "~/.jupyter/jupyter_notebook_config.py\n"
     ]
    }
   ],
   "source": [
    "%ls ~/.jupyter/jupyter_notebook_config.py"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "# Configuration file for jupyter-notebook.\n",
      "\n",
      "#-------------------------------------------------------\n",
      "# Application(SingletonConfigurable) configuration\n",
      "#-------------------------------------------------------\n",
      "\n",
      "## This is an application.\n",
      "\n",
      "## The date format used by logging formatters\n",
      "#c.Application.log_datefmt = '%Y-%m-%d %H:%M:%S'\n",
      "\n",
      "[...]\n",
      "\n",
      "#-------------------------------------------------------\n",
      "# JupyterApp(Application) configuration\n",
      "#-------------------------------------------------------\n",
      "\n",
      "## Base class for Jupyter applications\n",
      "\n",
      "## Answer yes to any prompts.\n",
      "#c.JupyterApp.answer_yes = False\n",
      "\n",
      "## Full path of a config file.\n",
      "#c.JupyterApp.config_file = ''\n",
      "\n",
      "...\n"
     ]
    }
   ],
   "source": [
    "%cat ~/.jupyter/jupyter_notebook_config.py"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```\n",
    "c.ContentsManager.untitled_notebook = 'MyNotebook'\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "notebook.json  tree.json\n"
     ]
    }
   ],
   "source": [
    "%ls ~/.jupyter/nbconfig/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"Cell\": {\n",
      "    \"cm_config\": {\n",
      "      \"lineNumbers\": false\n",
      "    }\n",
      "  },\n",
      "  \"Notebook\": {\n",
      "    \"Header\": false,\n",
      "    \"Toolbar\": false\n",
      "  }\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "%cat ~/.jupyter/nbconfig/notebook.json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "%%javascript\n",
    "var cell = Jupyter.notebook.get_selected_cell();\n",
    "var config = cell.config;\n",
    "var patch = {\n",
    "      CodeCell:{\n",
    "        cm_config: {autoCloseBrackets: false}\n",
    "      }\n",
    "    }\n",
    "config.update(patch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"Cell\": {\n",
      "    \"cm_config\": {\n",
      "      \"lineNumbers\": false\n",
      "    }\n",
      "  },\n",
      "  \"Notebook\": {\n",
      "    \"Header\": false,\n",
      "    \"Toolbar\": false\n",
      "  },\n",
      "  \"CodeCell\": {\n",
      "    \"cm_config\": {\n",
      "      \"autoCloseBrackets\": false\n",
      "    }\n",
      "  }\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "%cat ~/.jupyter/nbconfig/notebook.json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'cm_config': {'autoCloseBrackets': False}}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from notebook.services.config import ConfigManager\n",
    "c = ConfigManager()\n",
    "c.get('notebook').get('CodeCell')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'Cell': {'cm_config': {'lineNumbers': False}},\n",
       " 'CodeCell': {'cm_config': {'autoCloseBrackets': True}},\n",
       " 'Notebook': {'Header': False, 'Toolbar': False}}"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.update('notebook', {\"CodeCell\":\n",
    "         {\"cm_config\": {\"autoCloseBrackets\": True}}})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"Cell\": {\n",
      "    \"cm_config\": {\n",
      "      \"lineNumbers\": false\n",
      "    }\n",
      "  },\n",
      "  \"Notebook\": {\n",
      "    \"Header\": false,\n",
      "    \"Toolbar\": false\n",
      "  },\n",
      "  \"CodeCell\": {\n",
      "    \"cm_config\": {\n",
      "      \"autoCloseBrackets\": true\n",
      "    }\n",
      "  }\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "%cat ~/.jupyter/nbconfig/notebook.json"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# There's more..."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# See also"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
